#include<bits/stdc++.h>
using namespace std;

bool isPrime[] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0};
bool vis[10];

void dfs(int num, int n, vector<int>& ans)
{
	if(num == n)
	{
		for(auto i:ans)
			cout<<i<<" ";
		cout<<endl;
		return ;
	}
	for(int i = 2;i <= n;i++)
	{
		if(vis[i])
			continue;
		if(num == n-1)
		{
			if(isPrime[i+ans[num-1]] && isPrime[i+ans[0]])
			{
				ans[num] = i;
				vis[i] = 1;
				dfs(num+1, n, ans);
				vis[i] = 0;
			}
		}
		else
		{
			if(num == 1 && isPrime[i+ans[num-1]])
			{
				ans[num] = i;
				vis[i] = 1;
				dfs(num+1, n, ans);
				vis[i] = 0;
			}
			else if(num != 1 && isPrime[i+ans[num-1]] && isPrime[i+ans[num+1]])
			{
				ans[num] = i;
				vis[i] = 1;
				dfs(num+1, n, ans);
				vis[i] = 0;
			}
		}
	}
}

int main()
{
	int n, cnt = 1;
	while(cin>>n)
	{
		memset(vis, 0, sizeof vis);
		vector<int> ans(n);
		cout<<"Case "<<cnt++<<":"<<endl;
		ans[0] = 1;
		vis[1] = 1;
		dfs(1, n, ans);
	}
	return 0;
}

